<template>
  <div class="recom" id="recom">
    <div class="recom_title">看了又看</div>
    <div class="recom_list">
      <div class="left_btn" @click="left_move">
        <img src="http://1.117.75.96:8080/goods/UI/arrows.png" alt="" />
      </div>
      <div class="right_btn" @click="right_move">
        <img src="http://1.117.75.96:8080/goods/UI/arrows1.png" alt="" />
      </div>
      <div class="swiperlist" v-if="recom.length != 0">
        <ul :style="{transform:`translateX(${-move_index*236}px)`}">
          <li
            v-for="(item, index) in recom"
            :key="index"
            @click="routerTo(item.gid)"
          >
            <img v-lazy="item.gurl" alt="" />
            <div class="name">{{ item.gname }}</div>
            <div class="sub">{{ item.tag }}</div>
            <div class="price">￥{{ item.gprice }}</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, ref } from "vue";
import { useRouter } from "vue-router";

let router=useRouter()

let props = defineProps(["recom"]);

let move_index = ref(0);

function left_move() {
  if (move_index.value - 1 >= 0)
  move_index.value--
}
function right_move() {
  if (move_index.value + 1 <= props.recom.length - 5)
  move_index.value++
}
function routerTo(gid) {
  router.push({ name: "Goods", params: { id: gid } });
}
</script>

<style lang="less" scoped>
.recom {
  margin-top: 80px;
  margin-bottom: 20px;
  position: relative;
  width: 1226px;
  margin: 0 auto;

  .recom_title {
    font-size: 14px;
    line-height: 20px;
    color: #2b2e36;
    padding-left: 10px;
    font-size: 16px;
  }

  .recom_title::before {
    content: '';
    width: 2px;
    height: 18px;
    background: #00a8ff;
    position: absolute;
    left: 0;
  }

  .recom_list {
    position: relative;
    padding: 0 20px;
    height: 320px;

    .left_btn {
      position: absolute;
      top: 50%;
      width: 20px;
      height: 84px;
      line-height: 84px;
      margin-top: -42px;
      text-align: center;
      background: rgba(153, 153, 153, 0.1);
      cursor: pointer;
      left: 0;

      img {
        display: inline-block;
        width: 20px;
        height: 20px;
      }
    }

    .right_btn {
      position: absolute;
      top: 50%;
      width: 20px;
      height: 84px;
      line-height: 84px;
      margin-top: -42px;
      text-align: center;
      background: rgba(153, 153, 153, 0.1);
      cursor: pointer;
      right: 0;

      img {
        display: inline-block;
        width: 20px;
        height: 20px;
      }
    }

    .swiperlist {
      position: relative;
      padding: 0 15px 0 16px;
      height: 100%;
      font-size: 0;
      white-space: nowrap;
      overflow: hidden;

      ul {
        position: relative;
        padding: 30px 0;
        transition: all 0.2s;

        li {
          display: inline-block;
          vertical-align: top;
          padding: 24px 24px 0;
          width: 220px;
          height: 260px;
          text-align: center;
          color: #2b2e36;
          background: #fff;
          margin-right: 16px;
          border: 1px solid rgba(43, 46, 54, 0.1);
          cursor: pointer;
          box-sizing: border-box;

          img {
            width: 145px;
            height: 145px;
            display: block;
            margin: 0 auto 10px;
          }

          .name {
            font-size: 14px;
            line-height: 20px;
            margin-bottom: 8px;
            width: auto;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            word-wrap: normal;
          }

          .sub {
            font-size: 12px;
            line-height: 1;
            opacity: 0.4;
            margin-bottom: 10px;
            width: auto;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            word-wrap: normal;
          }

          .price {
            font-size: 14px;
            line-height: 20px;
            color: #ea334f;
          }
        }

        li:hover {
          box-shadow: 0px 8px 20px 0px rgb(84 86 96 / 10%);
        }
      }
    }
  }
}
</style>
